<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>系统常态化运行评分系统</title>
    <link rel="stylesheet" href="../component/pear/css/pear.css" />
    <style>
        .expand.pear-btn:hover {
            color: currentColor;
            background: none;
        }

        .expand.pear-btn {
            border: 1px solid rgba(255, 255, 255, 0)
        }
        .layui-table-box button {
            font-size: 12.5px !important;
            float: left;
            margin-right: 5px; /* 根据需要调整间距 */
        }
    
    </style>
    <script>

    </script>
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-header">评分任务基本信息</div>
        <div class="layui-card-body">
            <div class="data-display">
                <div class="data-item">
                    <span class="data-key"><strong>矿区/矿井:</strong></span>
                    <span class="data-value" id="mineName"></span>
                </div>
                <div class="data-item">
                    <span class="data-key"><strong>评分日期:</strong></span>
                    <span class="data-value" id="checkTime"></span>
                </div>
                <div class="data-item">
                    <span class="data-key"><strong>任务名称:</strong></span>
                    <span class="data-value" id="taskName"></span>
                </div>
                <div class="data-item">
                    <span class="data-key"><strong>自评权重后总分:</strong></span>
                    <span class="data-value" id="zpScoreWeight"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-table-box">
                <button id="batchZpCommit" class="pear-btn pear-btn-primary pear-border-blue pear-btn-xs" title="选择下面一个或多个系统，对多个系统评分后提交，一旦提交除管理员外，本人无法修改！">
                    <i class="layui-icon layui-icon-success"></i>
                    批量提交(自评)
                </button>
                <button id="batchZpBhCommit" class="pear-btn pear-btn-primary pear-border-blue pear-btn-xs" title="选择下面一个或多个系统，对提交的多个系统评分进行驳回，只能管理员操作！">
                    <i class="layui-icon layui-icon-success"></i>
                    批量驳回(自评)
                </button>
                <button id="batchZpTaskCommit" class="pear-btn pear-btn-primary pear-border-blue pear-btn-xs" title="无需选择下面的系统，直接对本次评分任务进行提交，只能管理员操作！">
                    <i class="layui-icon layui-icon-success"></i>
                    提交评分任务(自评)
                </button>
                <button id="batchHyCommit" class="pear-btn pear-btn-primary pear-border-blue pear-btn-xs" title="选择下面一个或多个系统，对多个系统评分核验后提交，一旦提交，无法修改！">
                    <i class="layui-icon layui-icon-success"></i>
                    批量提交(核验)
                </button>
                <button id="batchHyBhCommit" class="pear-btn pear-btn-primary pear-border-blue pear-btn-xs" title="选择下面一个或多个系统，对提交的多个系统评分进行驳回，只能管理员操作！">
                    <i class="layui-icon layui-icon-success"></i>
                    批量驳回(核验)
                </button>
                <button id="batchHyTaskCommit" class="pear-btn pear-btn-primary pear-border-blue pear-btn-xs" title="无需选择下面的系统，对多个系统评分核验后提交，一旦提交，无法修改！">
                    <i class="layui-icon layui-icon-success"></i>
                    提交评分任务(核验)
                </button>
              </div>
            <table id="user-table" lay-filter="user-table"></table>
        </div>
    </div>



    <script src="../component/layui/layui.js"></script>
    <script src="../component/pear/pear.js"></script>
    <script src="../scripts/utils/request.js"></script>
    <script src="../scripts/utils/auth.js"></script>
    <script src="../scripts/pfsystem.js"></script>
    <script>
        var $, table, form, drawer, popup, notice, laydate
        layui.use(['table', 'form', 'jquery', 'drawer', 'popup', 'notice', 'laydate'], function () {
            table = layui.table;
            form = layui.form;
            $ = layui.jquery;
            drawer = layui.drawer;
            popup = layui.popup;
            notice = layui.notice;
            laydate = layui.laydate;
            var taskType = null
            var state=null
            var id = getUrlParams('id');
            postAjaxNoSuccessTipAsync('/api/pf/details', { "id": id }, function (response) {
                layui.$('#mineName').text(response.data.mineName);
                layui.$('#checkTime').text(response.data.checkTime);
                layui.$('#taskName').text(response.data.taskName);
                taskType = response.data.taskType
                state=response.data.state
                showBatchButton(response.data.state,response.data.taskType);
            }, null);


            function showBatchButton(state,taskType){
                let roleType= localStorage.getItem("roleType");
                let isManager= localStorage.getItem("isManager");
                $("#batchZpCommit").hide();
                $("#batchZpBhCommit").hide();
                $("#batchZpTaskCommit").hide();
                $("#batchHyCommit").hide();
                $("#batchHyBhCommit").hide();
                $("#batchHyTaskCommit").hide();
                if(roleType==4){
                    if(state==1){
                        $("#batchZpCommit").show();
                        if(isManager=='true'){
                            $("#batchZpBhCommit").show();
                            $("#batchZpTaskCommit").show();
                        }
                    }
                }else if(roleType==3&&taskType==2){
                    if(state==2){
                        $("#batchHyCommit").show();
                        if(isManager=='true'){
                            $("#batchHyBhCommit").show();
                            $("#batchHyTaskCommit").show();
                        }
                    }
                }
            }
            table.render({
                id: "user-table",
                elem: '#user-table',
                url: baseURL + '/api/pf/systemList',
                method: 'post',
                contentType: 'application/json',
                page: false,
                loading: true,
                headers: {
                    token: localStorage.getItem("token")
                },
                request: {
                    pageName: 'pageIndex', // page
                    limitName: 'pageSize', // limit
                },
                where: {
                    "id": id
                },
                cols: getColByTaskType(taskType,state),
                skin: 'grid',
                toolbar: false,
                defaultToolbar: [],
                done: function (res, curr, count) {
                    validToken(res);
                    $('#zpScoreWeight').html(res.totalRow.pfScoreWeight);
                }
            });


            /**
             * 每行的按钮
             */
            table.on('tool(user-table)', function (obj) {

                console.log(obj.data);
                const totalScore = obj.data.totalScore;
                const weight = obj.data.weight;
                const id = obj.data.id;
                const systemId = obj.data.systemId;
                const systemName = obj.data.systemName;


                if (obj.event === 'zp') {
                    const type = 'zp';
                    const url = encodeURI(`/page/pfsystemdetails.html?id=${id}&systemId=${systemId}&systemName=${systemName}&totalScore=${totalScore}&weight=${weight}`);
                    parent.layui.admin.addTab('zp' + systemId + id, systemName + '(自评)', url);
                    parent.layui.admin.refresh('zp' + systemId + id);
                } else if (obj.event === 'hy') {
                    const url = encodeURI(`/page/pfsystemDetailKQ.html?id=${id}&systemId=${systemId}&systemName=${systemName}&totalScore=${totalScore}&weight=${weight}`);
                    parent.layui.admin.addTab('hy' + systemId + id, systemName + '(核验)', url);
                    parent.layui.admin.refresh('hy' + systemId + id);
                } else if (obj.event === 'zpcheck') {
                    const type = 'check';
                    const url = encodeURI(`/page/pfsystemdetails.html?id=${id}&systemId=${systemId}&systemName=${systemName}&totalScore=${totalScore}&weight=${weight}`);
                    parent.layui.admin.addTab('zpcheck' + systemId + id, systemName + '(自评)', url);
                    parent.layui.admin.refresh('zpcheck' + systemId + id);
                } else if (obj.event === 'hycheck') {
                    if (taskType == 1) {
                        const type = 'check';
                        const url = encodeURI(`/page/pfsystemdetails.html?id=${id}&systemId=${systemId}&systemName=${systemName}&totalScore=${totalScore}&weight=${weight}`);
                        parent.layui.admin.addTab('zpcheck' + systemId + id, systemName + '(自评)', url);
                        parent.layui.admin.refresh('zpcheck' + systemId + id);
                    } else {
                        const url = encodeURI(`/page/pfsystemDetailKQ.html?id=${id}&systemId=${systemId}&systemName=${systemName}&totalScore=${totalScore}&weight=${weight}`);
                        parent.layui.admin.addTab('hycheck' + systemId + id, systemName + '(核验)', url);
                        parent.layui.admin.refresh('hycheck' + systemId + id);
                    }
                }else if(obj.event ==='download'){
                    if(obj.data.zpRemark==null||obj.data.zpRemark==''){
                        notice.error('该系统未上传佐证材料！');
                        return;
                    }
                    postAjaxNoSuccessTip('/api/file/previewFilePf',{'id':obj.data.zpRemark},function(data){
                        window.open(data.data);
                    });

                }

            });
            /**
             * 新增操作
             */
            table.on('toolbar(user-table)', function (obj) {
                if (obj.event === 'refresh') {
                    window.refresh();
                }
            });

            $('#batchZpCommit').on('click', function(){
                batchCommit();
            });
            $('#batchHyCommit').on('click', function(){
                batchCommit();
            });


            $('#batchZpBhCommit').on('click', function(){
                batchBhCommit();
            });
            $('#batchHyBhCommit').on('click', function(){
                batchBhCommit();
            });

            $('#batchZpTaskCommit').on('click', function(){
                batchTaskCommit();
            });
            $('#batchHyTaskCommit').on('click', function(){
                batchTaskCommit();
            });

            /**
             * 提交评分任务
             */
            function batchTaskCommit(){
                let reqData={
                    pfId:id
                }
                layer.confirm('确定提交本次评分任务？一旦提交无法修改。', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    postAjax('/api/pf/batchTaskCommit',reqData,function(data){
                        parent.layui.admin.refresh('pfSystem' + id);
                    },null);
                });
            }

            /**
             * 批量驳回
             */
            function batchBhCommit(){
                let checkStatus = table.checkStatus('user-table');
                let data = checkStatus.data; // 获取选中的数据
                if(data.length === 0){
                    notice.error('请选择需要提交的数据');
                    return;
                }
                let systemIdList= data.map(x=>x.systemId);
                let reqData={
                    pfId:id,
                    systemIdList:systemIdList
                }
                layer.confirm('确定汇报选中系统的评分结果？驳回后，需通知相关业务人员重新提交。', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    postAjax('/api/pf/batchBhCommit',reqData,function(data){
                        parent.layui.admin.refresh('pfSystem' + id);
                    },null);
                });
            }

            /**
             * 批量提交
             */
            function batchCommit(){
                let checkStatus = table.checkStatus('user-table');
                let data = checkStatus.data; // 获取选中的数据
                if(data.length === 0){
                    notice.error('请选择需要提交的数据');
                    return;
                }
                let systemIdList= data.map(x=>x.systemId);
                let reqData={
                    pfId:id,
                    systemIdList:systemIdList
                }
                layer.confirm('确定提交选中系统的评分结果？一旦提交，无法修改。', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.close(index);
                    postAjax('/api/pf/batchCommit',reqData,function(data){
                        parent.layui.admin.refresh('pfSystem' + id);
                    },null);    
                });
            }

            window.refresh = function (param) {
                table.reload('user-table');
            };

        })
    </script>
    <style>
        .data-display {
            display: flex;
            flex-direction: unset;
            margin: 10px 0;
            justify-content: space-around;
        }

        .data-item {
            display: flex;
            margin-bottom: 10px;
            /* 项之间的间距 */
        }

        .data-key {
            margin-right: 10px;
            /* 键与值之间的间距 */
            font-weight: bold;
            /* 加粗 */
        }

        .data-value {
            color: #333;
            /* 值的颜色 */
        }
    </style>
</body>

</html>